package zhtt.manyToMany1d;

import org.junit.Test;
import zhtt.JunitTestUtil;

/**
 * Created by zhtt on 2017/4/11.
 */
public class JunitTest1 extends JunitTestUtil {

    @Test
    /**
     * 1、【student】表插入
     * 2、【course】表插入
     * 3、【中间表】插入
     */
    public void save1(){
        try{
            session.beginTransaction();
            Course course=new Course("ad");
            Student student=new Student("zaa");
            student.getCourseSet().add(course);
            session.save(student);
            session.getTransaction().commit();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Test
    /**
     * 1、【course】表插入
     * 2、【student】表插入
     * 3、【中间表】插入
     */
    public void save2(){
        try{
            session.beginTransaction();
            Course course=new Course("ad");
            Student student=new Student("zaa");
            course.getStudentSet().add(student);
            session.save(course);
            session.getTransaction().commit();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
